function _toConsumableArray(t) {
    if (Array.isArray(t)) {
        for (var e = 0, o = Array(t.length); e < t.length; e++) o[e] = t[e];
        return o;
    }
    return Array.from(t);
}

var g, pages, app = getApp(), page = app.page, request = app.util.request, route = app.route,_tools = require("../../utils/tools");

function getGoodsList() {
  
    var user = wx.getStorageSync("userInfo")
    var o = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : 1;
    request({
        url: "Shop",
        data: {
            page: o,
            type_id: 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "",
            number: app.config.goods_number,
            user_id: user.id
        },
        showLoading: !1,
        success: function(t) {
            var e = g.data.good_list;
            t = t.good_list, e && 1 != o && (t = [].concat(_toConsumableArray(e), _toConsumableArray(t))), 
            g.setData({
                good_list: t
            }), wx.stopPullDownRefresh(), t.length && o * app.config.goods_number >= t[0].num && g.setData({
                isLoad: !0
            });
        }
    });
}

page({
    data: {
        type_index: 0,
        isLoad: !1
    },
    watch:{
      userInfo:function(newValue){
        if(newValue){
          getGoodsList()
        }
      }
    },
    onLoad: function(t) {
       getApp().setWatcher(this.data, this.watch);
        pages = 1, (g = this).options && g.options.id ? (g.getData(1, g.options.id), 
        g.setData({
            type_id: {
                id: g.options.id
            }
        }), wx.setNavigationBarTitle({
            title: g.options.title
        })) : request({
            url: "ShopType",
            showLoading: !1,
            success: function(t) {
                g.setData({
                    good_type: [ {
                        id: "",
                        title: "全部"
                    } ].concat(_toConsumableArray(t.good_type))
                }), g.getData();
            }
        });
        console.log(g.data.userInfo)
        let userInfo = wx.getStorageSync("userInfo")
        if(userInfo){
          request({
            url: "AddUsersLog",
            data: {
              user_id: userInfo.id,
              url: '/u_pages/shop/index',
              title: "商城"
            },
            success: function(a) {
            }
          })
        }
    },
    getData(page=1,type = ''){
      if(g.data.system.is_force_login){
        return void (0, _tools.verifyLogin)({
          success: function() {
            console.log(888)
            getGoodsList(page,type)
          }
        });
      } else {
        getGoodsList(page,type)
      }
    },
    onPullDownRefresh: function() {
        g.setData({
            type_index: 0,
            isLoad: !1
        }), pages = 1, g.onLoad();
    },
    selectType: function(t) {
        var e = (t = t.currentTarget.dataset.data)[0], t = t[1];
        g.setData({
            type_index: e,
            isLoad: !1
        }), g.getData(pages = 1, t);
    },
    onReachBottom: function() {
        !g.data.isLoad && pages++ && g.getData(pages, g.data.good_type[g.data.type_index].id);
    },
    onShareAppMessage: function(t) {
        return {
            title: g.data.system.xcx_name,
            path: g.route + "?pid=" + app.userInfo.id
        };
    },
    onShareTimeline: function() {
        return {
            title: g.data.system.xcx_name,
            query: "pid=" + app.userInfo.id
        };
    }
});